Imports XL.Common
Imports XL.Common.Utils

Public Class S_01_00401
    Inherits XL.DB.Utils.BaseService
    Public Shared Function GetInstance() As S_01_00401

        Dim result As S_01_00401
        If AssetVisionXAuto.Decls.CURRENT_DB_TYPE = XL.DB.DBDecl.DBType.Remoting Then

            result = CType(Activator.GetObject(GetType(S_01_00401), _
                String.Format("tcp://{0}/S_01_00401.remote", _
                    SysInfo.ReadLocalSysInfo(CommDecl.XLSLVN_SYSTEM_REMOTE_SERVICE_URL))),  _
                S_01_00401)

            If result.ValidateAuthPassword(CommDecl.CURRENT_LOCAL_REMOTE_AUTH_PASSWORD) = False Then
                Dim ex As New XLException(XLException.ErrorClassify.ReadDataError)
                ex.SetMessage(CommDecl.MSG_ALERT_REMOTE_AUTH_DENIED)
                Throw ex
            End If

        Else

            result = New S_01_00401
        End If

        Return result

    End Function

    Public Enum LCs
        None
        ChooseDepartment
        ChooseStaff
        Utld0004
        Utld0005
    End Enum


    Public Function ServLoadStaffList( _
        ByVal valDepartmentID As String, _
        ByVal valIsDimission As Boolean, _
        ByRef refStaffList As AssetVisionXAuto.FTs.FT_M_AV_STAFF, _
        ByVal valChoosePrincipalOnly As Boolean _
        ) As String

        Try

      
            Dim staffConditions As New AssetVisionXAuto.Facade.AfBizMaster.ConditionOfM_AV_STAFF(XL.DB.Utils.Condition.LogicOperators.Logic_And)
            staffConditions.Add(AssetVisionXAuto.Facade.AfBizMaster.M_AV_STAFFColumns.DEPARTMENT_IDColumn, "=", valDepartmentID)
            If valChoosePrincipalOnly = True Then
                Dim principalIDs = AssetVisionXAuto.Facade.AfBizMaster.GetM_AV_DEPARTMENT_CVListDistinct( _
                    Nothing, _
                    AssetVisionXAuto.Facade.AfBizMaster.M_AV_DEPARTMENTColumns.PRINCIPALColumn)

                staffConditions.Add(AssetVisionXAuto.Facade.AfBizMaster.M_AV_STAFFColumns.STAFF_IDColumn, True, principalIDs)
            End If

            staffConditions.Add(AssetVisionXAuto.Facade.AfBizMaster.M_AV_STAFFColumns.IS_DIMISSIONColumn, "=", valIsDimission)

            AssetVisionXAuto.Facade.AfBizMaster.FillFT_M_AV_STAFF(staffConditions, refStaffList)

        Catch ex As XL.Common.Utils.XLException

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)

            'WinTK.OutputLog("XL Exception", logContentBuilder.ToString())

            Return logContentBuilder.ToString()

        Catch ex As Exception

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)


            Return logContentBuilder.ToString()

        End Try

        Return String.Empty

    End Function


    Public Function ServInitDisplay( _
         ByRef refChooseStaffList As AssetVisionXAuto.FTs.FT_M_AV_STAFF, _
         ByRef refChooseDepartmentList As AssetVisionXAuto.FTs.FT_M_AV_DEPARTMENT, _
         ByRef refAddressAloneDeptLevel As Integer _
         ) As String

        Try

            'AssetVisionXAuto.Facade.AfBizMaster.FillFT_M_AV_DEPARTMENT(Nothing, refChooseDepartmentList)
            'AssetVisionXAuto.Facade.AfBizMaster.FillFT_M_AV_STAFF(Nothing, refChooseStaffList)
            'refAddressAloneDeptLevel = CommTK.FInteger(SysInfo.ReadShareSysInfo(Decls.SVN_ADDRESS_ALONE_DEPT_LEVEL))

            ''Dim servResult As String = _
            '    Me._service.ServUtld0001(

            'If servResult.length > 0 Then
            '    Return servResult
            'End If


        Catch ex As XL.Common.Utils.XLException

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)

            'WinTK.OutputLog("XL Exception", logContentBuilder.ToString())

            Return logContentBuilder.ToString()

        Catch ex As Exception

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)


            Return logContentBuilder.ToString()

        End Try

        Return String.Empty

    End Function


    Public Function ServSaveLocationDepartment( _
        ByVal valDepartmentID As String, _
        ByRef refLocationList As AssetVisionXAuto.FTs.FT_M_AV_LOCATION, _
        ByRef refCancelLocationIDList As String, _
        ByVal valForceSave As Boolean _
        ) As String


        Try

            Dim assetCondition As New AssetVisionXAuto.Facade.AfBizMaster.ConditionOfT_AV_ASSET(XL.DB.Utils.Condition.LogicOperators.Logic_And)
            Dim locationIDs As New ArrayList
            Dim cancelLocationIDs As New ArrayList


            For Each locationRow As AssetVisionXAuto.FTs.FT_M_AV_LOCATIONRow In refLocationList.FindRowsSelecting(True)
                assetCondition.Clear()
                assetCondition.Add(AssetVisionXAuto.Facade.AfBizMaster.T_AV_ASSETColumns.CURRENT_LOCATIONColumn, "=", locationRow.LOCATION_ID)

                If valForceSave = False AndAlso _
                    AssetVisionXAuto.Facade.AfBizMaster.GetT_AV_ASSETCount(assetCondition) > 0 Then
                    cancelLocationIDs.Add(locationRow.LOCATION_ID)
                    Continue For
                End If

                locationIDs.Add(locationRow.LOCATION_ID)
            Next

            refCancelLocationIDList = CommTK.ALToStr(cancelLocationIDs)
            Dim locationCondition As New AssetVisionXAuto.Facade.AfBizMaster.ConditionOfM_AV_LOCATION(XL.DB.Utils.Condition.LogicOperators.Logic_And)
            locationCondition.Add(AssetVisionXAuto.Facade.AfBizMaster.M_AV_LOCATIONColumns.LOCATION_IDColumn, True, locationIDs)

            AssetVisionXAuto.Facade.AfBizMaster.ReviseM_AV_LOCATIONData( _
                locationCondition, _
                AssetVisionXAuto.Facade.AfBizMaster.M_AV_LOCATIONColumns.DEPARTMENT_IDColumn, _
                valDepartmentID)


            locationCondition.Clear()
            locationCondition.Add(AssetVisionXAuto.Facade.AfBizMaster.M_AV_LOCATIONColumns.DEPARTMENT_IDColumn, "=", valDepartmentID)
            locationCondition.Add(AssetVisionXAuto.Facade.AfBizMaster.M_AV_LOCATIONColumns.LOCATION_IDColumn, False, locationIDs)

            AssetVisionXAuto.Facade.AfBizMaster.ReviseM_AV_LOCATIONData( _
                locationCondition, _
                AssetVisionXAuto.Facade.AfBizMaster.M_AV_LOCATIONColumns.DEPARTMENT_IDColumn, _
                String.Empty)


            AssetVisionXService.Facade.OpMP.ExecuteMP_AV_EXECUTE_SYNC_ASSET_RUNNER_BY_LOCATION()

        Catch ex As XL.Common.Utils.XLException

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)

            'WinTK.OutputLog("XL Exception", logContentBuilder.ToString())

            Return logContentBuilder.ToString()

        Catch ex As Exception

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)


            Return logContentBuilder.ToString()

        End Try

        Return String.Empty

    End Function


    Public Function ServSaveLoginDenyStatus( _
        ByVal valBindingStaffList As AssetVisionXAuto.FTs.FT_M_AV_STAFF _
        ) As String

        Try

            For Each bindingRow As AssetVisionXAuto.FTs.FT_M_AV_STAFFRow In valBindingStaffList
                AssetVisionXAuto.Facade.AfBizMaster.ReviseM_AV_STAFFRow( _
                    bindingRow.STAFF_ID, _
                    AssetVisionXAuto.Facade.AfBizMaster.M_AV_STAFFColumns.LOGIN_DENYColumn, _
                    bindingRow.LOGIN_DENY)
            Next

        Catch ex As XL.Common.Utils.XLException

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)

            'WinTK.OutputLog("XL Exception", logContentBuilder.ToString())

            Return logContentBuilder.ToString()

        Catch ex As Exception

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)


            Return logContentBuilder.ToString()

        End Try

        Return String.Empty
    End Function


    Public Function ServBizUtld0005( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0005(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0006( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0006(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0007( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0007(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0008( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0008(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0009( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0009(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0010( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0010(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0011( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0011(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0012( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0012(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0013( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0013(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0014( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0014(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0015( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0015(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0016( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0016(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0017( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0017(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0018( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0018(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0019( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0019(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0020( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0020(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


End Class
